package wicketcool.converter;

import japa.parser.ASTHelper;
import japa.parser.ast.body.FieldDeclaration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wicketcool.model.WCLField;

/**
 * User: rabbit
 * Date: Aug 3, 2009
 */
@Service
public class DefaultFieldConverter implements FieldConverter {

    @Autowired
    private ModifierConverter modifierConverter;
    @Autowired
    private AnnotationsConverter annotationsConverter;
    @Autowired
    private TypeConverter typeConverter;

    public FieldDeclaration createFieldDeclaration(WCLField field) {

        FieldDeclaration fieldDeclaration = ASTHelper.createFieldDeclaration(
                modifierConverter.modifierToCUModifierInt(field.getModifier()),
                typeConverter.createType(field.getType()),
                field.getName());
        fieldDeclaration.setAnnotations(annotationsConverter.createAnnotationsExpr(field.getAnnotations()));
        return fieldDeclaration;
    }
}
